package com.meilai.project.mapper.personnel.org;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.meilai.project.entity.personnel.org.Department;
import com.meilai.project.vo.system.WebDepartmentForChooseVO;
import com.meilai.project.vo.personnel.org.WebDepartmentListVO;
import com.meilai.project.vo.system.WebDepartmentVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DepartmentMapper extends BaseMapper<Department> {
    List<WebDepartmentVO> selectPageList(Page<WebDepartmentVO> page, @Param("name") String name, @Param("status") Integer status);

    List<WebDepartmentForChooseVO> getForChooseList();

    @Select("select * from department where name=#{name}")
    Department selectByCompanyName(@Param("name") String name);

    @Select("select * from department where pid=#{pid} and name=#{name}")
    Department selectByPidAndName(@Param("pid") long pid, @Param("name") String name);

    @Select("SELECT DISTINCT id FROM department WHERE ISNULL(deleted_at) AND `status`=1 AND FIND_IN_SET (id,queryDepartmentChildrenIdsById(#{department_id}))")
    List<Long> getChildrenIdsById(@Param("department_id") Long department_id);

    List<WebDepartmentListVO> getDepartmentsByUserId(@Param("user_id") Long user_id);

    /**
     * 查询部门全路径名称
     *
     * @param id 部门id
     */
    @Select("select `queryDepartmentNamesById` (#{id})")
    String getDepFullNameById(@Param("id") Long id);

    List<Long> getDeptIdByUserId(@Param("userId") Long userId);
}
